package com.zang.blogz.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zang.blogz.annotation.OptLog;
import com.zang.blogz.constant.OptTypeConstant;
import com.zang.blogz.entity.JobLog;
import com.zang.blogz.model.input.ro.JobLogSearchRO;
import com.zang.blogz.result.Result;
import com.zang.blogz.service.JobLogService;
import com.zang.blogz.utils.SearchQueryInit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 定时任务调度日志表 前端控制器
 * </p>
 *
 * @author 朵橙i
 * @since 2022-09-04
 */
@RestController
@RequestMapping("/blogz/jobLog")
@Api(tags = "定时任务执行日志模块")
public class JobLogController {

    @Autowired
    private JobLogService jobLogService;

    @GetMapping("/admin/jobLog")
    @ApiOperation(value = "查询定时任务执行日志", notes = "查询定时任务执行日志")
    public Result<IPage<JobLog>> queryJobLogList(@RequestBody JobLogSearchRO jobLogSearchRO,
                                                 @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                 @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize){

        IPage<JobLog> iPage = new Page<>(pageNo, pageSize);

        QueryWrapper<JobLog> queryWrapper = SearchQueryInit.getQueryWrapper(jobLogSearchRO, JobLog.class);

        return Result.ok(jobLogService.queryJobLogList(iPage, queryWrapper));

    }

    @PostMapping("/admin/deleteByIds")
    @OptLog(optType = OptTypeConstant.REMOVE)
    @ApiOperation(value = "批量删除定时任务执行日志", notes = "删除定时任务执行日志")
    public Result<Boolean> deleteByIds(@RequestBody List<Integer> ids){

        return jobLogService.deleteByIds(ids);
    }

    @PostMapping("/admin/deleteById")
    @OptLog(optType = OptTypeConstant.REMOVE)
    @ApiOperation(value = "删除定时任务执行日志", notes = "删除定时任务执行日志")
    public Result<Boolean> deleteById(@RequestParam("id") Integer id){

        return jobLogService.deleteById(id);
    }

    @GetMapping("/admin/detailed")
    @ApiOperation(value = "获取定时任务执行日志详细内容", notes = "获取定时任务执行日志详细内容")
    public Result<JobLog> detailed(@RequestParam("id") Integer id){

        return jobLogService.detailed(id);
    }


}
